<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.buss.core.dic.CheckStatus" %>
<%@include file="../includes/tag.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">    
    <title>业务信息管理平台</title>
    <script type="text/javascript" src="<%=basePath%>resources/lib/jquery/jquery.js"></script>
    <script type="text/javascript" src="<%=basePath%>resources/lib/webui/buss.ui.core.js"></script>
    <script type="text/javascript" src="<%=basePath%>resources/lib/webui/buss.ui.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/jqgrid/js/i18n/grid.locale-cn.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/jqgrid/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/webui/buss.validatebox.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/public.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/goodsUtils.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/customerUtils.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/calendar/WdatePicker.js"></script>
	
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/styles/themes/buss-ui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/jqgrid/css/jquery-ui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/jqgrid/css/ui.jqgrid.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/styles/public.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/styles/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/calendar/skin/WdatePicker.css">
    
    <script type="text/javascript">
    	var basePath = "<%=basePath%>";
    	$(document).ready(function(){

    		setMasterGridData();

    		setDetailGridData("-1");
    		resize();
    		$(window).resize(resize);
    		
    		
    		$("#search-btn").button({iconCls:'icon-search',handler:function(){
    			var params = $("form[name='_searchForm']").serialize();
				$("#tabledata").jqGrid("setGridParam",{url:'<%=basePath%>admin/purchaseorder/listMaster.do?' + params,page:1}).trigger("reloadGrid");
				$("#detail_tabledata").jqGrid("setGridParam",{page:1,url:"<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/-1.do"}).trigger("reloadGrid");
    		}});
    		
    		$("#search-clear").button({iconCls:'icon-cancel',handler:function(){
    			$("form[name='_searchForm']").resetForm();
    			$("#search-btn").trigger("click");
    		}});
    		
    		$("#search-adv-btn").button({iconCls:'icon-search',handler:function(){
    			
    		}});
    		
    		$("#detail_product-btn").button({iconCls:'icon-add',handler:function(){    			
    			goods.selectGoods("0",true,function(rsData){
    				$("input[name='goodsId']").val(rsData.id);
    				$("input[name='goods_name']").val(rsData.name);    				
    			})
    		}})
    		
    		$("#detail_search-btn").button({iconCls:'icon-search',handler:function(){    			
    			var jsonParam = syscore.formToJson($("#_detail-searchForm"));
    			
				$("#detail_tabledata").jqGrid("setGridParam",{page:1,postData:jsonParam}).trigger("reloadGrid");
    		}})
    		
    		$("#detail_clear-btn").button({iconCls:'icon-cancel',handler:function(){    			
    			$("form[name='_detail-searchForm']").find("input[name='goodsId']").val("");
    			$("form[name='_detail-searchForm']").find("input[name='goods_name']").val("");
    			$("#detail_search-btn").trigger("click");
    		}})
    		
    		$("#add-btn").button({iconCls:'icon-add',handler:function(){
    			addOrEditOrder("add");    			
    		}});
    		
			$("#edit-btn").button({iconCls:'icon-edit',handler:function(){
				var selRows = $("#tabledata").jqGrid('getGridParam',"selrow");
				if(selRows == null){
					$.alert('提示','你没有选择要修改的数据!',300,140,'info');
					return;
				}
				var rowData = $("#tabledata").jqGrid("getRowData",selRows);
				if(rowData.checkStatusVal != "untreated" && rowData.checkStatusVal != "notAudited"){
					$.alert("提示","只能修改状态为未处理和未通过的订单信息!",300,140,"info");
					return;
				}
				addOrEditOrder("edit",selRows);
    		}});
			
			$("#del-btn").button({iconCls:'icon-remove',handler:function(){
				var selRows = $("#tabledata").jqGrid('getGridParam',"selrow");
				if(selRows == null){
					$.alert('提示','你没有选择要修改的数据!',300,140,'info');
					return;
				}
				var url = "<%=basePath%>admin/purchaseorder/delMaster.do";
				$.confirm('提示','确认要删除选中数据吗?',300,140,function(){
					$.post(url,{ids:selRows[0]},function(rsData){
						if(rsData.message.code != "0"){
							$.alert("错误",rsData.message.mess,300,140,"error");
							return;
						}
						$("#tabledata").jqGrid("setGridParam",{page:1}).trigger("reloadGrid");
						$("#detail_tabledata").jqGrid("setGridParam",{page:1,url:"<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/-1.do"}).trigger("reloadGrid");
					},"json");
				});
    		}});
			
			$("#checkPending-btn").button({iconCls:'icon-ok',handler:function(){
				var selRows = $("#tabledata").jqGrid('getGridParam',"selrow");
				if(selRows == null){
					$.alert('提示','你没有选择需要待审核的数据!',300,140,'info');
					return;
				}
				var rowData = $("#tabledata").jqGrid("getRowData",selRows);
				if(rowData.checkStatusVal != "untreated" && rowData.checkStatusVal != "notAudited"){
					$.alert("提示","只能待审核的状态为未处理和未通过的订单信息!",300,140,"info");
					return;
				}
				$.confirm('提示','确认要申请该订单审核吗?',300,140,function(){
					var url = "<%=basePath%>admin/purchaseorder/check.do";
					$.post(url,{id:selRows,status:'unAudited'},function(rsData){
						if(rsData.message.code != "0"){
							$.alert("错误","申请审核订单时失败,原因:" + rsData.message.mess,300,140,"error");
							return;
						}
						$("#tabledata").jqGrid().trigger("reloadGrid");
					},"json");
				});
			}});
    	});
    	
    	/**新增或自改采购订单信息*/
    	function addOrEditOrder(type,orderId){
    		var url = "<%=basePath%>admin/purchaseorder/addpage.do";
    		var saveUrl = "<%=basePath%>admin/purchaseorder/add.do";
    		var title = "新建采购订单信息";
    		if(type != "add"){
    			url = "<%=basePath%>admin/purchaseorder/editpage.do?id=" + orderId;
    			saveUrl = "<%=basePath%>admin/purchaseorder/editMaster.do";
    			title = "编辑采购订单信息";
    		}else{
    			orderId = '-1';
    		}
    		var dlg = $("<div/>").dialog({
    			height:500,
    			width:900,
    			title:title,
    			closable:true,
    			minimizable:false,
    			collapsible:false,
    			iconCls:'icon',
    			loadUrl:url,
    			buttons:[
							{text:'保  存',type:'button',iconCls:'icon-save',handler:function(){
								if(dlg.find("input[name='orderNumber']").val().trim() == "自动生成订单号"){
									dlg.find("input[name='orderNumber']").val("");
								}
								var formData = dlg.find("form").serialize();								
								var rowIds = dlg.find("#product_tabledata").jqGrid("getDataIDs");		
								if(rowIds.length == 0){
									$.alert("提示","你没有选择商品，不能保存!",300,140,"info");
									return;
								}
								var detail = "";
								for(var index in rowIds){				
									var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",rowIds[index]);
									var goodsId = rowData["goods.id"];
									var quantity = rowData["quantity"];
									var price = rowData["price"];
									var discountRate = rowData["discountRate"];
									var intro = rowData["intro"];
									detail += "&";
									detail += "details["+index+"].goods.id=" + goodsId + "&";
									detail += "details["+index+"].quantity=" + quantity + "&";
									detail += "details["+index+"].price=" + price + "&";
									detail += "details["+index+"].discountRate=" + discountRate + "&";
									detail += "details["+index+"].intro=" + intro;
								}
								formData += detail;
								$.post(saveUrl,formData,function(rs){
									if(rs.message.code != '0'){
										$.alert("错误","保存数据失败,原因：" + rs.message.mess,300,140,"error");
										return;
									}
									$("#tabledata").jqGrid("setGridParam",{page:1}).trigger("reloadGrid");
									$("#detail_tabledata").jqGrid("setGridParam",{page:1,url:"<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/-1.do"}).trigger("reloadGrid");
									dlg.dialog("destroy");
								},"json");
							}},
							{text:'关  闭',type:'button',iconCls:'icon-cancel',handler:function(){
								dlg.dialog("destroy");
							}}
    			         ],
    			onLoad:function(){
    				if(type == "add"){
    					dlg.find("input[name='orderNumber']").val("自动生成订单号");
    					dlg.find("input[name='orderNumber']").css("color","rgb(102, 102, 102)");
    				}
    				dlg.find("input[name='orderNumber']").blur(    					
    					function(){
    						var val = $(this).val().trim();
    						if(val == ""){
    							$(this).val("自动生成订单号");
    							$(this).css("color","rgb(102, 102, 102)");
    						}
    					}
    				);
    				dlg.find("input[name='orderNumber']").focus(function(){
   						var val = $(this).val().trim();
   						if(val == "自动生成订单号"){
   							$(this).val("");
   							$(this).css("color","");
   						}
    				})
    				dlg.find("#sel-product-btn").button({iconCls:'icon-add',handler:function(){
						goods.selectGoods("0",false,function(rsDatas,showEdit){
							var cnt = rsDatas.length;
							for(var i = 0;i < cnt;i++){
								var goodsNum = rsDatas[i].goodsNum;
								var goodsPrice = rsDatas[i].goodsPrice;
								var goodsScale = rsDatas[i].goodsScale;
								var goods = rsDatas[i].goods;
								var gridData = {
										goods:goods,
										quantity:goodsNum,
										price:goodsPrice,
										discountRate:goodsScale,
										intro:''
								}
								var ind = dlg.find("#product_tabledata").jqGrid("getInd",goods.id);
								if(ind != false){
									continue;
								}
								dlg.find("#product_tabledata").jqGrid("addRowData",goods.id,gridData);
								//edit_goodsDetail
								dlg.find(".edit_goodsDetail").unbind();
								dlg.find(".edit_goodsDetail").click(function(){
									var id = $(this).attr("id");
									var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",id);
									showEditQuantity(rowData);						
								});
							}
							if(showEdit){
								var goods = rsDatas[0].goods;
								var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",goods.id);
								showEditQuantity(rowData);								
							}
							computeAmount(dlg.find("#product_tabledata"));
						});
    				}});
    				dlg.find("#del-product-btn").button({iconCls:'icon-remove',handler:function(){
    					var selRows = dlg.find("#product_tabledata").jqGrid('getGridParam',"selarrrow");
    					if(selRows == 0){
    						$.alert('提示','你没有选择要修改的数据!',300,140,'info');
    						return;
    					}
    					$.confirm('提示','确认要删除选中数据吗?',300,140,function(){
    						var str = "";
    						for(var i = selRows.length;i >= 0;i--){
    							var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",selRows[i]);
    							if(rowData && rowData.id){
    								$("<input name='removeDetailIds' value='"+rowData.id+"'/>").appendTo(dlg.find("#removeDetailIds"));
    							}
    							dlg.find("#product_tabledata").jqGrid("delRowData",selRows[i]);
    						}
    						computeAmount(dlg.find("#product_tabledata"));
    					});	
    				}});
    				dlg.find("#query-product-btn").button({iconCls:'icon-search',handler:function(){    					
    					goods.selectGoodsByBarcode(function(rsData){    
    						var data = {
    								goods:rsData,
    								quantity:1,
    								price:rsData.price,
    								discountRate:100,
    								intro:'',
    						}
    						var ind = dlg.find("#product_tabledata").jqGrid("getInd",rsData.id);
    						
    						if(ind == false){
    							dlg.find("#product_tabledata").jqGrid("addRowData",rsData.id,data);    							
    						}
    						var tmpData = dlg.find("#product_tabledata").jqGrid("getRowData",rsData.id);
							showEditQuantity(tmpData);
							computeAmount(dlg.find("#product_tabledata"));
    					})
    				}});
    				dlg.find("select[name='branch.id']").combo({width:128,editable:false});
    				dlg.find("select[name='salesManId']").combo({width:128,editable:false});
    				dlg.find("#sel_supplier").button({iconCls:'icon-search',handler:function(){
    					customer.selectCustomer("supplier",function(rsData){
    						var supplierId = rsData["id"];
    						var supplierName = rsData["name"];
    						dlg.find("input[name='supplier.id']").val(supplierId);
    						dlg.find("input[name='supplier.name']").val(supplierName);
    					});
    				}});
    				queryOrderDetailForEdit(dlg,orderId);
    			}
    		});
    		dlg.dialog("loadPage");
    	}
    	
    	
    	
    	
    	
    	function computeAmount(targetObj){
    		var rowIds = $(targetObj).jqGrid("getDataIDs");							
			var discountRateAmount  = 0;
			var amount = 0;
			for(var rowId in rowIds){				
				var rowData = $(targetObj).jqGrid("getRowData",rowIds[rowId]);
				var quantity = parseFloat(rowData["quantity"]);								
				var price = parseFloat(rowData["price"]);
				discountRateAmount += parseFloat(rowData["amount"]);
				amount += (quantity * price);								
			}
			$("input[name='allowance']").val(parseFloat(amount - discountRateAmount).toFixed(2));
			$("input[name='amount']").val(parseFloat(discountRateAmount).toFixed(2));
    	}
    	
    	function showEditQuantity(rowData){    		
			var id = rowData["goods.id"];
			var name=rowData["goods.goods.name"];
			var salesProp = rowData["goods.propContextValueClear"];
			var quantity=rowData["quantity"];
			var price = rowData["price"];
			var scale = rowData["discountRate"];
			var intro = rowData["intro"];
			editQuantityOrPrice(id,quantity,price,scale,name,salesProp,intro);
    	}
    	
    	
    	/**查询采购订单明细信息(用于编辑页面)*/
    	function queryOrderDetailForEdit(dlg, orderId){
    		var url = "<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/" + orderId + ".do";
    		var colNames = ["id","商品编码","商品名称","单位","销售属性","数量","单价","折扣率(%)","采购金额","备注","操作"];
    		
    		var colModel = [
    		                {name:'id',hidden:true},
    		                {name:"goods.id",index:"goodsId",width:80,align:'left',sortable:false},
    		                {name:"goods.goods.name",index:'goodsName',width:120,align:'left',sortable:false},
    		                {name:'goods.goods.entryUnit',index:'goodsEntryUnit',width:80,align:'center',sortable:false},
    		                {name:'goods.propContextValueClear',index:'',width:350,align:'left',sortable:false},
    		                {name:'quantity',index:'quantity',width:80,align:'right',sortable:false,editable: true,formatter:'number'},
    		                {name:'price',index:'price',width:80,align:"right",sortable:false,editable: true,formatter:'number'},
    		                {name:'discountRate',index:'discountRate',width:80,align:'right',sortable:false,editable: true,formatter:'number'},
    		                {name:'amount',width:100,align:'right',sortable:false,formatter:function(cellVal,opt,rowObj){
    		                	return (rowObj.quantity * (rowObj.price * (rowObj.discountRate / 100))).toFixed(2);
    		                }},
    		                {name:'intro',width:120,align:'left',sortable:false},
    		                {name:'editrow',width:60,align:'center',formatter:function(cellVal,opt,rowObj){
    		                	return "<a href='javascript:void(0);' class='edit_goodsDetail' id='"+rowObj.goods.id+"' style='text-decoration: underline;color:blue;'>编辑</a>";
    		                }}
    		                ];
    		var h = dlg.find("#product_tabledata").parent().height();
    		var w = dlg.find("#product_tabledata").parent().width();
    		dlg.find("#product_tabledata").jqGrid({
    			url:url,
    			datatype:'json',
    			mtype:'post',
    			height:h - 10,
    			width:w,
    			multiselect:true,
    			multiboxonly:true,
    			autoencode:true,
    			forceFit:true,
    			rowNum:0,
    			colNames:colNames,
    			colModel:colModel,
    			jsonReader:{
    				id:'goods.id',
    				root:'result.data',
    				page:'result.page.curPageNo',
    				total:'result.page.totalPage',
    				repeatitems:false
    			},
    			ondblClickRow: function(rowid,iRow,iCol,e){
    				var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",rowid);
    				var id = rowData["goods.id"];
    				var name=rowData["goods.goods.name"];
    				var salesProp = rowData["goods.propContextValueClear"];
    				var quantity=rowData["quantity"];
    				var price = rowData["price"];
    				var scale = rowData["discountRate"];
    				var intro = rowData["intro"];
    				editQuantityOrPrice(id,quantity,price,scale,name,salesProp,intro);
    				
    			},
    			loadComplete:function(){
    				dlg.find(".edit_goodsDetail").click(function(){
						var id = $(this).attr("id");
						var rowData = dlg.find("#product_tabledata").jqGrid("getRowData",id);
	    				var id = rowData["goods.id"];
	    				var name=rowData["goods.goods.name"];
	    				var salesProp = rowData["goods.propContextValueClear"];
	    				var quantity=rowData["quantity"];
	    				var price = rowData["price"];
	    				var scale = rowData["discountRate"];
	    				var intro = rowData["intro"];
	    				editQuantityOrPrice(id,quantity,price,scale,name,salesProp,intro);
					});
    				computeAmount(dlg.find("#product_tabledata"));
    			}
    		});
    	}
    	
    	function editQuantityOrPrice(id,oldQuantity,oldPrice,oldScale,goodsName,salesProp,intro){
    		var panel = "<div><table width='100%' align='center' cellpadding='0' cellspacing='8'>";
    			panel += "<tr><td align='right'>商品名称：</td><td align='left'><input class='text' name='name' size='35' readonly='true'/></td></tr>";
    			panel += "<tr><td align='right'>销售属性：</td><td align='left'><input class='text' name='saleProp' size='35' readonly='true'/></td></tr>";
    			panel += "<tr><td align='right'>数量：</td><td align='left'><input class='text numberFormat' name='quantity' size='35'/></td></tr>";
    			panel += "<tr><td align='right'>单价：</td><td align='left'><input class='text numberFormat' name='price' size='35'/></td></tr>";
    			panel += "<tr><td align='right'>折扣率：</td><td align='left'><input class='text numberFormat' name='scale' size='35'/></td></tr>";
    			panel += "<tr><td align='right'>备注：</td><td align='left'><textarea name='intro' rows='3' cols='50' class='textarea'/></td></tr>";
    			panel += "</table></div>";
    		var dlg = $(panel).dialog({
    			modal:true,
    			header:true,
    			height:300,
    			width:500,
    			title:"修改数量/价格",
    			closable:true,
    			minimizable:false,
    			collapsible:false,
    			iconCls:'icon',
    			buttons:[
						{text:'确  定',type:'button',iconCls:'icon-ok',handler:function(){
							var rowData = $("#product_tabledata").jqGrid("getRowData",id);
							var name = dlg.find("input[name='name']").val();
							var salesProp = dlg.find("input[name='saleProp']").val();
		    				var quantity=dlg.find("input[name='quantity']").val();
		    				var price = dlg.find("input[name='price']").val(); 
		    				var scale = dlg.find("input[name='scale']").val(); 
		    				var intro = dlg.find("textarea[name='intro']").val(); 	    
		    				
		    				var amount = parseFloat(quantity) * (parseFloat(price) * (parseFloat(scale) / 100));
		    				rowData["quantity"] = quantity;
		    				rowData["price"] = price;
		    				rowData["discountRate"] = scale;
		    				rowData["intro"] = intro;
		    				$("#product_tabledata").jqGrid("setRowData",id,rowData);
		    				computeAmount($("#product_tabledata"));
		    				dlg.dialog("destroy");
						}},
						{text:'取  消',type:'button',iconCls:'icon-cancel',handler:function(){
							dlg.dialog("destroy");
						}}
    			         ]
    		})
    		dlg.find("input[name='quantity']").focus();
    		dlg.find("input[name='name']").val(goodsName);
    		dlg.find("input[name='saleProp']").val(salesProp);
    		dlg.find("input[name='quantity']").val(parseFloat(oldQuantity).toFixed(2));
    		dlg.find("input[name='price']").val(parseFloat(oldPrice).toFixed(2));
    		dlg.find("input[name='scale']").val(parseFloat(oldScale).toFixed(2));
    		dlg.find("textarea[name='intro']").val(intro);
    		dlg.find(".numberFormat").validatebox("numberFormat");
    	}
    	
    	/**订单信息列表*/
    	function setMasterGridData(){
    		var params = $("form[name='_searchForm']").serialize();
    		var url = "<%=basePath%>admin/purchaseorder/listMaster.do?" + params;
    		var colNames = ['chk',"订单单号","订单日期","订单金额","折让额","实际金额","审核状态","审核时间","采购库房","录入人","录入时间"];
    		var colModel = [
							{name:'checkStatusVal',hidden:true,formatter:function(cellVal,opt,rowObj){								
								return rowObj.checkStatus;
							}},
    		                {name:'orderNumber',index:'orderNumber',width:80,align:'left'},
    		                {name:'orderDate',index:'orderDate',width:100,align:'center'},
    		                {name:'totalAmount',index:"",width:70,align:'right',sortable:false,formatter:function(cellVal,opt,rowObj){
    		                	return (rowObj.amount + rowObj.allowance).toFixed(2);
    		                }},    		                
    		                {name:'allowance',index:'allowance',width:60,align:'right',formatter:'number'},    	
    		                {name:'amount',index:'amount',width:60,align:'right',formatter:'number'},
    		                {name:'checkStatus',index:'checkStatus',width:60,align:'center',formatter:syscore.formaterCheckStatus},
    		                {name:'checkDate',index:'checkDate',width:100,align:'center'},
    		                {name:'branch.name',index:'branchId',sortable:false,width:100},
    		                {name:'createUserName',index:'createUserName',align:'center',width:80},
    		                {name:'createDate',index:'createDate',align:'center',width:100,formatter:'date',formatoptions:{srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}}
    		                ];
    		syscore.setGridData($("#tabledata"),$("#tablepage"),url,colNames,colModel,false,0,'id',null,function(id){
    			$("#detail_tabledata").jqGrid("setGridParam",{page:1,url:"<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/" + id + ".do"}).trigger("reloadGrid");
    		});    		
    	}
    	
    	/**订单明细信息*/
    	function setDetailGridData(orderId){
    		var url = "<%=basePath%>admin/purchaseorder/queryOrderDetailForEdit/" + orderId + ".do";
    		var colNames = ["id","商品编码","商品名称","单位","销售属性","数量","单价","折扣率(%)","采购金额","备注"];    		
    		var colModel = [
    		                {name:'id',hidden:true},    		                
    		                {name:"goods.id",index:"goodsId",width:80,align:'left',sortable:false},
    		                {name:"goods.goods.name",index:'goodsName',width:120,align:'left',sortable:false},
    		                {name:'goods.goods.entryUnit',index:'goodsEntryUnit',width:80,align:'center',sortable:false},
    		                {name:'goods.propContextValueClear',index:'',width:350,align:'left',sortable:false},
    		                {name:'quantity',index:'quantity',width:80,align:'right',sortable:false,editable: true,formatter:'number'},
    		                {name:'price',index:'price',width:80,align:"right",sortable:false,editable: true,formatter:'number'},
    		                {name:'discountRate',index:'discountRate',width:80,align:'right',sortable:false,editable: true,formatter:'number'},
    		                {name:'amount',width:100,align:'right',sortable:false,formatter:function(cellVal,opt,rowObj){
    		                	return (rowObj.quantity * (rowObj.price * (rowObj.discountRate / 100))).toFixed(2);
    		                }},
    		                {name:'intro',width:150,align:'left',sortable:false}
    		                ];
    		syscore.setGridData($("#detail_tabledata"),$("#detail_tablepage"),url,colNames,colModel,false,0,'id'); 
    	}
    	
    	function resize(){
    		$("#p_container").width($(window).width());
			var h = $(window).height() - $(".nav_curloc").outerHeight() - $(".nav_search").outerHeight() - $(".nav_btn_bar").outerHeight() - 10;
			$("#detail_tabledata").jqGrid("setGridHeight",h - $(".context").height() - 58);
			$("#detail_tabledata").jqGrid("setGridWidth",$(window).width() - 12);
			$("#tabledata").jqGrid("setGridHeight",200);
			$("#tabledata").jqGrid("setGridWidth",$(window).width() - 12);
		}
    </script>
    <style type="text/css">
    	 html,body{
    	 	overflow: hidden;
    	 }
    </style>
</head>
<body>
  	<div id="p_container" style="height:100%;position:relative;">
  		<div class="nav_curloc">
	    	<label>您的当前位置：<bstag:navbar menuId="${menuid}"/></label>
	    </div>
	    <div class="nav_search" style="height: 65px;padding-top: 3px;">
	   		<form action="" name="_searchForm">
		    	<table height="100%" cellpadding="0" cellspacing="6">
		    		<tr>
		    			<td valign="middle">订单时间：</td>
		    			<td valign="middle">
		    				<input type="text" size="18" maxlength="100" class="text Wdate" id="orderStartDate" name="orderStartDate" onfocus="var orderEndDate=$dp.$('orderEndDate');WdatePicker({isShowClear:false,readOnly:true,isShowClear:true,onpicked:function(){orderEndDate.focus();},maxDate:'#F{$dp.$D(\'orderEndDate\')}'})"/>&nbsp;至
		    				<input type="text" size="18" maxlength="100" class="text Wdate" id="orderEndDate" name="orderEndDate" onfocus="WdatePicker({isShowClear:false,readOnly:true,isShowClear:true,minDate:'#F{$dp.$D(\'orderStartDate\')}'})"/>
		    			</td>
		    			<td valign="middle" style="padding-left:10px;">审核状态：</td>
		    			<td valign="middle">
		    					<input type="radio" id="all" name="checkStatus" checked="checked" value=""/><label for="all">所有</label>
		    				<%
		    					for(CheckStatus status : CheckStatus.values()){
		    				%>
		    					<input type="radio" id="<%=status %>" name="checkStatus" value="<%=status%>"/><label for="<%=status%>"><%=status.getValue() %></label>
		    				<%
		    					}
		    				%>
		    			</td>
		    		</tr>
		    		<tr>
		    			<td valign="middle">录入时间：</td>
		    			<td valign="middle" align="left">
		    				<input type="text" id="createStartDate" value="${createStartDate }" size="18" maxlength="100" class="text Wdate" name="createStartDate" onfocus="var orderEndDate=$dp.$('createEndDate');WdatePicker({isShowClear:false,readOnly:true,isShowClear:true,onpicked:function(){createEndDate.focus();},maxDate:'#F{$dp.$D(\'createEndDate\')}'})"/>&nbsp;至
		    				<input type="text" id="createEndDate" value="${createEndDate }" size="18" maxlength="100" class="text Wdate" name="createEndDate" onfocus="WdatePicker({isShowClear:false,readOnly:true,isShowClear:true,minDate:'#F{$dp.$D(\'createStartDate\')}'})"/>
		    			</td>
		    			<td style="padding-left:5px;" colspan="2">
		    				<a id="search-btn" href="javascript:void(0);" style="margin-left:6px;">查 询</a>
		    				<a id="search-clear" href="javascript:void(0);" style="margin-left:2px;">清 空</a>
		    				<a id="search-adv-btn" href="javascript:void(0);" style="margin-left:20px;">高级查询</a>
		    			</td>
		    		</tr>
		    	</table>
	    	</form>
	    </div>
	    <div class="nav_btn_bar">
	    	<table height="100%" cellpadding="0" cellspacing="0">
	    		<tr>
	    			<td valign="middle">
	    				<a id="add-btn" href="javascript:void(0);">新 增</a>
	    			</td>
	    			<td valign="middle"" style="padding-left:5px;">
	    				<a id="edit-btn" href="javascript:void(0);">修 改</a>
	    			</td>
	    			<td valign="middle" style="padding-left:5px;">
	    				<a id="del-btn" href="javascript:void(0);">删 除</a>
	    			</td>
	    			<td valign="middle" style="padding-left:15px;">
	    				<a id="checkPending-btn" href="javascript:void(0);">待审核</a>
	    			</td>
	    		</tr>
	    	</table>
	    </div>
	    <div class="context" style="height:250px">
	    	<table id="tabledata"></table>
	    	<div id="tablepage"></div>
	    </div>
	    <div class="nav_search" style="height: 28px;padding-bottom:4px; margin-left:5px;margin-right:5px;">
	    	<form id="_detail-searchForm" name="_detail-searchForm" action="">
	    		<table height="100%" cellpadding="0" cellspacing="5">
	    			<tr>
	    				<td valign="middle">选择商品：</td>
	    				<td align="left">	    					
	    					<input type="hidden" name="goodsId">
	    					<input type="text" class="text" name="goods_name" readonly="readonly" size="22"/>
	    					<a id="detail_product-btn" href="javascript:void(0);">选择商品</a>
	    				</td>
	    				<td style="padding-left:5px;" colspan="2">
		    				<a id="detail_search-btn" href="javascript:void(0);" style="margin-left:6px;">查 询</a>
		    				<a id="detail_clear-btn" href="javascript:void(0);" style="margin-left:2px;">清 空</a>
		    			</td>
	    			</tr>
	    		</table>
	    	</form>
	    </div>
	    <div class="detail_context" style="margin-left:5px;">
	    	<table id="detail_tabledata"/>
	    	<div id="detail_tablepage"></div>
	    </div>
	    
  	</div> 
    
  </body>
</html>